import moment from 'moment';
import fx from '../utils/fx'

export default [
  {
    title: '股票代码',
    dataIndex: 'symbol',
    sorter: true,
  },
  {
    title: '交易类型',
    dataIndex: 'tradeType',
    sorter: true,
    render: text => ({ Buy: '做多', Sell: '做空' })[text],
  },
  {
    title: '买入价格',
    dataIndex: 'buyPrice',
    render: text => text.toFixed(2),
    sorter: true,
  },
  {
    title: '卖出价格',
    dataIndex: 'sellPrice',
    render: text => text.toFixed(2),
    sorter: true,
  },
  {
    title: '交易量',
    dataIndex: 'quantity',
    sorter: true,
  },
  {
    title: '费用',
    dataIndex: 'fee',
    render: text => text.toFixed(2),
    sorter: true,
  },
  {
    title: '盈亏',
    dataIndex: 'pnl',
    render: text => fx.colorMoney(text.toFixed(2)),
    sorter: true,
  },
  {
    title: '收益率',
    sorter: false,
    render: (text, row) => {
      const { tradeType, buyPrice, sellPrice, quantity, pnl } = row;
      return fx.formatRoi(pnl / (buyPrice * quantity));
    },
  },
  {
    title: '建仓时间',
    dataIndex: 'openTime',
    sorter: true,
    render: text => moment(new Date(text)).format('YYYY-MM-DD HH:mm:ss'),
  },
  {
    title: '平仓时间',
    dataIndex: 'closeTime',
    sorter: true,
    render: text => moment(text).format('YYYY-MM-DD HH:mm:ss'),
  },
    {
    title: '持仓时间',
    render: (text, row) => {
      const { openTime, closeTime } = row;
      return fx.formatSeconds((moment(closeTime) - moment(openTime)) / 1000);
    },
  },
];
